<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%--头部内容开始--%>
<jsp:include page="head.jsp"/>
<%--头部内容结束--%>
<%--中间内容开始--%>
<div class="layui-container fly-marginTop fly-user-main">
    <jsp:include page="manger_left.jsp"/>


    <div class="fly-panel fly-panel-user" pad20>

        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title" id="LAY_mine">
                <li data-type="mine-jie" lay-id="index" class="layui-this">评论回复</li>
            </ul>
            <div class="layui-tab-content" style="padding: 20px 0;">
                <!-- 博客列表 -->
                <div class="layui-tab-item layui-show">

                    <div style="height: 10px;">
                    </div>
                    <div class="demoTable">
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="startTime" placeholder="起始时间" autocomplete="off" >
                        </div>
                        至
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="endTime" placeholder="结束时间" autocomplete="off">
                        </div>
                        <div class="layui-inline">
                            <input class="layui-input" name="id" placeholder="标题/用户" id="demoReload" onfocus="this.placeholder=''" onblur="this.placeholder='标题/用户'" autocomplete="off">
                        </div>
                        <button class="layui-btn" data-type="reload" id="search">搜索</button>
                    </div>
                    <%--表格相关--%>
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-primary layui-btn-xs" target="_blank" lay-event="detail">查看</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                    <%--左上角工具栏--%>
                    <script type="text/html" id="toolbarDemo">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm" lay-event="getCheckData"><i class="layui-icon">&#xe640;</i>批量删除</button>
                        </div>
                    </script><%--表格操作--%>
                </div>
                <!-- 我的文件列表结束 -->
            </div>

        </div>
    </div>
</div>
<%--中间内容结束--%>
<%--底部内容开始--%>
<jsp:include page="bottom.jsp"/>
<%--底部内容结束--%>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js" ></script>
<script src="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>

<%--表格渲染--%>
<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,toolbar: '#toolbarDemo'
            ,url:'${pageContext.request.contextPath}/blog/student/reply_list.do'
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            , id: 'test'
            ,title: '评论回复管理表'
            ,cols: [[
                {fixed: 'left',type: 'checkbox',width:'5%'}
                ,{field:'rId', title:'ID',type:"numbers", width:'10%', unresize: true, align:'center'}
                ,{field:'user', title:'发布用户', width:'15%', sort: true, align:'center',templet: '<div>{{d.user.uNickName}}</div>'}
                ,{field:'rContent', title:'内容', width:'30%', sort: true, align:'center',edit:'true'}
                ,{field:'rCreateTime', title:'时间', width:'20%', sort: true, align:'center'}
                ,{title:'操作', toolbar: '#barDemo', width:'20%', align:'center'}
            ]]
            ,page: true,
            text: {
                none: '暂无相关数据'
            }
        });
        //数据表格重载
        // 执行搜索，表格重载
        var $ = layui.$,active={
            reload:function(){
                var demoReload = $('#demoReload').val();
                var startTime = $('#startTime').val();
                var endTime = $('#endTime').val();
                // console.log('demoReload='+demoReload+'startTime='+startTime+'endTime='+endTime);
                table.reload('test', {
                    method: 'get'
                    , where: {
                        'keywords': demoReload
                        ,'startTime':startTime
                        ,'endTime':endTime
                        ,'time':new Date().valueOf()
                    }
                    , page: {
                        curr: 1
                    }
                });
            }
        }

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    if(data.length!=0){
                        var ids = [];//回复评论id
                        for (var i = 0; i < data.length; i++) { //循环筛选出id
                            ids.push(data[i].rId);
                        }
                        //发送删除请求
                        layer.confirm("确认要删除这些评论回复吗，删除后不能恢复", { title: "删除确认" }, function(index){
                            senddel(ids);
                            return false;
                        });
                    }else{
                        layer.msg("您还未选择数据！",{icon: 5});
                    }

                    // layer.alert(JSON.stringify(uName));
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(data.uId);
            if(obj.event === 'del'){
                layer.confirm('真的删除此条评论回复么', function(index){
                    var ids = data.rId;
                    senddel(ids);
                    return false;
                });
            }else if(obj.event === 'detail'){//查看
                console.log(data);
                window.open("${pageContext.request.contextPath}/blog/content.do?bId="+data.rBId);
            }
        });
        /*删除请求*/
        function senddel(ids){
            $.ajax({
                url: "${pageContext.request.contextPath}/blog/student/reply_delete.do",
                type: "post",
                data: 'ids='+ids,
                success: function (result) {
                    if (result.msg == 200) {
                        //关闭弹框
                        //layer.close(index);
                        layer.msg("删除成功", {icon: 6});
                        table.reload('test',{});
                    } else {
                        layer.msg("删除失败", {icon: 5});
                    }
                }
            });
        };

    });
    /*选择时间*/
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startTime'
            , theme: 'molv'
        });
        laydate.render({
            elem: '#endTime'
            , theme: 'molv'
        });
    });

</script>


